home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1999 March / EnigmA AMIGA RUN 35 (1999)(G.R. Edizioni)(IT)[!][issue 1999-03].iso / earcd / grafica / amhelios / patch3.cpp < prev    next >
C/C++ Source or Header  |  1999-01-01  |  3KB  |  110 lines

  1. ////////////////////////////////////////////////////////////
  2. //
  3. //  PATCH3.CPP - 3-D Patch Classes
  4. //
  5. //  Version:    1.03A
  6. //
  7. //  History:    94/08/23 - Version 1.00A release.
  8. //              94/12/16 - Version 1.01A release.
  9. //              95/02/05 - Version 1.02A release.
  10. //              95/07/21 - Version 1.02B release.
  11. //              96/02/14 - Version 1.02C release.
  12. //              96/04/01 - Version 1.03A release.
  13. //
  14. //  Compilers:  Microsoft Visual C/C++ Professional V1.5
  15. //              Borland C++ Version 4.0
  16. //
  17. //  Author:     Ian Ashdown, P.Eng.
  18. //              byHeart Software Limited
  19. //              620 Ballantree Road
  20. //              West Vancouver, B.C.
  21. //              Canada V7S 1W3
  22. //              Tel. (604) 922-6148
  23. //              Fax. (604) 987-7621
  24. //
  25. //  Copyright 1994-1996 byHeart Software Limited
  26. //
  27. //  The following source code has been derived from:
  28. //
  29. //    Ashdown, I. 1994. Radiosity: A Programmer's
  30. //    Perspective. New York, NY: John Wiley & Sons.
  31. //
  32. //  It may be freely copied, redistributed, and/or modified
  33. //  for personal use ONLY, as long as the copyright notice
  34. //  is included with all source code files.
  35. //
  36. ////////////////////////////////////////////////////////////
  37.  
  38. #include "patch3.h"
  39.  
  40. void Vertex3::CalcNormal()      // Calculate vertex normal
  41. {
  42.   ElemList *pelist = pelhd;     // Element list pointer
  43.  
  44.   // Sum element normals
  45.   while (pelist != NULL)
  46.   {
  47.     normal += pelist->GetElemPtr()->GetNormal();
  48.     pelist = pelist->GetNext();
  49.   }
  50.  
  51.   normal.Norm();        // Normalize vector
  52. }
  53.  
  54. void Element3::CalcArea()       // Calculate element area
  55. {
  56.   Vector3 temp;     // Temporary 3-D vector
  57.  
  58.   Vector3 va(pvertex[0]->GetPosn(), pvertex[1]->GetPosn());
  59.   Vector3 vb(pvertex[0]->GetPosn(), pvertex[2]->GetPosn());
  60.  
  61.   temp = Cross(va, vb);
  62.   area = (float) (temp.Length() / 2.0);
  63.  
  64.   if (IsQuad() == TRUE)
  65.   {
  66.     Vector3 vc(pvertex[3]->GetPosn(),
  67.         pvertex[0]->GetPosn());
  68.  
  69.     temp = Cross(vb, vc);
  70.     area += (float) (temp.Length() / 2.0);
  71.   }
  72. }
  73.  
  74. void Element3::CalcNormal()     // Calculate element normal
  75. {
  76.   Vector3 va(pvertex[0]->GetPosn(), pvertex[1]->GetPosn());
  77.   Vector3 vb(pvertex[0]->GetPosn(), pvertex[2]->GetPosn());
  78.  
  79.   normal = Cross(va, vb);
  80.   normal.Norm();
  81. }
  82.  
  83. void Patch3::CalcCenter()       // Calculate patch centroid
  84. {
  85.   int i;            // Loop index
  86.   int num_vert;     // Number of vertices
  87.   Vector3 cv;       // Centroid vector
  88.   Point3 p3;
  89.  
  90.   num_vert = GetNumVert();
  91.  
  92.   // Initialize centroid vector to origin
  93.   cv = Vector3(0.0, 0.0, 0.0);
  94.  
  95.   // Determine patch centroid
  96.   for (i = 0; i < num_vert; i++)
  97.   {
  98.     p3 = pvertex[i]->GetPosn();
  99.     cv += Vector3(p3);
  100.   }
  101.  
  102.   cv /= (double) num_vert;
  103.  
  104.   // Convert centroid vector to 3-D point
  105.   center.SetX(cv.GetX());
  106.   center.SetY(cv.GetY());
  107.   center.SetZ(cv.GetZ());
  108. }
  109.  
  110.